package com.huangfu.learning.javabase.java.java8;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

/**
 * Created with IntelliJ IDEA.
 * Author: huangfu.daohui
 * Date: 2018/9/12
 * Time: 15:02
 * Version: 1.0
 * Description:双冒号::就是把方法当做参数传到stream内部，使stream的每个元素都传入到该方法里面执行一下。
 **/
public class DoubleColon {
    public static void printValur(String str) {
        System.out.println("print value : " + str);
    }

    public static void main(String[] args) {
        List<String> al = Arrays.asList("a", "b", "c", "d");
        al.forEach(AcceptMethod::printValur);
        //下面的方法和上面等价的
        Consumer<String> methodParam = AcceptMethod::printValur; //方法参数
        al.forEach(x -> methodParam.accept(x));//方法执行accept
    }
}

class AcceptMethod {

    public static void printValur(String str) {
        System.out.println("print value : " + str);
    }

    public static void main(String[] args) {
        List<String> al = Arrays.asList("a", "b", "c", "d");
        for (String a : al) {
            AcceptMethod.printValur(a);
        }
        //下面的for each循环和上面的循环是等价的
        al.forEach(x -> {
            AcceptMethod.printValur(x);
        });
    }
}